﻿
SET QUOTED_IDENTIFIER ON
GO

SET ANSI_NULLS ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_SMS_SetMsgReceiver_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_SMS_SetMsgReceiver_V2];
GO
CREATE PROCEDURE [dbo].[sproc_SMS_SetMsgReceiver_V2]
    @MsgID         int,
    @ReceiverXml   xml,
    @Type          int
            
/*

============================================================
功能:    短消息发送
参数:
    @MsgID        int	:    消息ID
    @ReceiverXml  xml	:    接收者字符串
    @Type         int             ;    1站内用户 2站外用户
注意:    @Receivers与@MobileNo必须一一对应
============================================================

*/

AS
BEGIN
SET NOCOUNT ON

/*
 * XML format:
 * <receiver>
 *  <r name="" mobileNo="" />
 * </receiver>
 */

INSERT INTO dbo.UDS_SMS_Receiver (MsgID, Receiver, MobileNo, Type, IsRead )
SELECT
	@MsgID,
	X.r.value(N'@name', 'nvarchar(50)'),
	X.r.value(N'@mobileNo', 'nvarchar(50)'),
	@Type,
	0 -- indicates this is a new message
FROM @ReceiverXml.nodes(N'/receiver/r') X(r);

END
GO